
from event import Event, ReadableEvent, WritableEvent, TimeoutEvent, IdentityGenerator
from buffer_event import BufferReadEvent, BufferWriteEvent


class EventCreator:
    ID_GENERATOR = IdentityGenerator()

    @staticmethod
    def from_readable(fno, readable_handler, persistent=True):
        return ReadableEvent(EventCreator.ID_GENERATOR.next(), fno, readable_handler, persistent)
    @staticmethod
    def from_writable(fno, writable_handler=None, persistent=False):
        return WritableEvent(EventCreator.ID_GENERATOR.next(), fno, writable_handler, persistent)
    @staticmethod
    def from_timeout(timeout_ms, timeout_handler, persistent=True):
        return TimeoutEvent(EventCreator.ID_GENERATOR.next(), timeout_ms, timeout_handler, persistent)

    @staticmethod
    def from_buffer_readable(transport, handler, buffer=None):
        return BufferReadEvent(EventCreator.ID_GENERATOR.next(), transport, handler, buffer)
    @staticmethod
    def from_buffer_writable(transport, handler, buffer=None):
        return BufferWriteEvent(EventCreator.ID_GENERATOR.next(), transport, handler, buffer)
